package com.lu.spzx.product.controller;

import com.lu.spzx.model.entity.product.Category;
import com.lu.spzx.model.entity.product.ProductSku;
import com.lu.spzx.model.vo.common.Result;
import com.lu.spzx.model.vo.common.ResultCodeEnum;
import com.lu.spzx.model.vo.h5.IndexVo;
import com.lu.spzx.product.service.CategoryService;
import com.lu.spzx.product.service.ProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value="/api/product/index")
@SuppressWarnings("all")
// 网关中已经配置,不需要重复配置
// @CrossOrigin
public class IndexController {

   @Autowired
   private CategoryService categoryService;

   @Autowired
   private ProductSkuService productSkuService;

   // 获取首页数据
   @GetMapping
   public Result<IndexVo> findData(){
      // 获取一级分类数据
      List<Category> categoryList = this.categoryService.findOneCategory();
      // 获取畅销商品列表
      List<ProductSku> productSkuList = this.productSkuService.findProductSkuBySale();

      IndexVo indexVo = new IndexVo() ;
      indexVo.setCategoryList(categoryList);
      indexVo.setProductSkuList(productSkuList);

      return Result.build(indexVo , ResultCodeEnum.SUCCESS);
   }

}